﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using IdentityServer4.Extensions;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Utility.Extensions;
namespace QuickFramework.UICore.Controllers.User
{
    /// <summary>
    /// 用户信息相关
    /// </summary>
    [Area("User")]
    public class UserInfoController : Shared.Contracts.AuthorizeControllerBase
    {
        Users.IDomain.IUserInfo m_IUserInfo = null;
        /// <summary>
        /// 
        /// </summary>
        public UserInfoController(Users.IDomain.IUserInfo userInfo)
        {
            m_IUserInfo = userInfo;
        }
        /// <summary>
        /// 获取用户信息
        /// url: /api/User/UserInfo/GetUserInfo
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetUserInfo()
        {
            var userInfo = await m_IUserInfo.GetUserInfo(this.User.GetDisplayName());

            return Ok(new
            {
                roles = new List<string> { "admin" },
                introduction = "I am a super administrator",
                avatar = "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
                name = userInfo.U_Name
            });
        }
        /// <summary>
        /// 修改密码
        /// url: /api/User/UserInfo/UpdatePwd
        /// </summary>
        /// <param name="userUpdatePwd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> UpdatePwd(Users.DTO.UserUpdatePwd userUpdatePwd)
        {
            userUpdatePwd.ID = this.User.GetDisplayName();
            var result = await m_IUserInfo.UpdatePwd(userUpdatePwd);
            return Ok(new { Result = result.Item1, Msg = result.Item2 });
        }
    }
}
